package com.sys.android.xmppmanager;

import java.util.Iterator;

import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.OfflineMessageManager;

import android.app.Activity;
/**
	离线消息
 */
public class OffLine {

	public static void offlinemsg(Activity c) {
		String log = XmppConnection.getConnection().getUser().split("@")[0];
		OfflineMessageManager offlineMessageManager = new OfflineMessageManager(
				XmppConnection.getConnection());
		try {
			System.out.println(offlineMessageManager.getMessageCount());
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			Iterator<Message> it = offlineMessageManager.getMessages();

			while (it.hasNext()) {
				Message message = it.next();
				System.out
						.println("收到离线消息, Received from 【" + message.getFrom()
								+ "】 message: " + message.getBody());
				String fromUser = message.getFrom().split("@")[0];
				String msg = message.getBody();
				

			}
			offlineMessageManager.deleteMessages();
		} catch (XMPPException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
